<template>
  <div class="container">
    <el-form
      :inline="true"
      :model="params"
      label-width="70px"
      label-position="left"
      size="mini"
      class="demo-form-inline"
      style="padding-top: 18px;"
    >
      <el-form-item label="批次ID">
        <el-input v-model="params.batchId" placeholder="批次ID" class="the-input"></el-input>
      </el-form-item>
      <el-form-item label="批次名称">
        <el-input v-model="params.batchName" placeholder="批次ID" class="the-input"></el-input>
      </el-form-item>
      <el-form-item label="申请人">
        <el-input v-model="params.applyName" placeholder="批次名称" class="the-input"></el-input>
      </el-form-item>
      <el-form-item label="申请时间">
        <el-date-picker v-model="params.createTime" type="month" placeholder="选择月份"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="doSearch">查询</el-button>
        <el-button type="primary" @click="doExport">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="tableData"
      style="width: 100%"
      border
      size="small"
      stripe
      :empty-text="emptyText"
    >
      <el-table-column prop label="优惠券批次ID" width="180"></el-table-column>
      <el-table-column prop label="批次名称" width="180"></el-table-column>
      <el-table-column prop label="优惠券金额" width="180"></el-table-column>
      <el-table-column prop label="优惠券限额" width="180"></el-table-column>
      <el-table-column prop label="优惠券类型" width="180"></el-table-column>
      <el-table-column prop label="使用商户" width="180"></el-table-column>
      <el-table-column prop label="申请数量" width="180"></el-table-column>
      <el-table-column prop label="发放数量" width="180"></el-table-column>
      <el-table-column prop label="使用率" width="180"></el-table-column>
      <el-table-column prop label="GMV" width="180"></el-table-column>
      <el-table-column prop label="使用金额" width="180"></el-table-column>
      <el-table-column prop label="客单价" width="180"></el-table-column>
      <el-table-column prop label="申请人" width="180"></el-table-column>
      <el-table-column prop label="有效期" width="280"></el-table-column>
    </el-table>
    <div class="pagination-area" style>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="params.pageSize"
        :current-page.sync="params.pageIndex"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
        :page-count="pageCount"
      ></el-pagination>
    </div>
    <el-dialog title="优惠券日志" :visible.sync="dialogVisible" width="800">
      <el-table :data="logs" border size="small" stripe>
        <el-table-column width="50" type="index" label="序号" align="center"></el-table-column>
        <el-table-column width="100" prop="createBy" label="操作人"></el-table-column>
        <el-table-column width="150" prop="operateDesc" label="操作类型"></el-table-column>
        <el-table-column prop="createTime" label="时间"></el-table-column>
        <el-table-column prop="remark" label="操作说明" width="100"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
/**
 * 优惠券数据统计的数据由甲方提供 后端暂未想好如何对接 暂时搁置
 */
import { getDataStatistics } from '@/api/coupon'
import { getStatusNameByStatus } from '@/utils/status'
export default {
  name: "couponList",
  data() {
    return {
      // 用于显示或隐藏日志弹窗
      dialogVisible: false,
      params: {
        // 每页条数
        pageSize: 10,
        // 页码
        pageIndex: 1,
        // 申请人
        applyName: '',
        // 创建时间
        createTime: '',
        // 优惠券批次id
        batchId: '',
        // 优惠券批次名称
        batchName: ''
      },
      emptyText: "",
      // 总条目数
      totalCount: 100,
      // 总页数
      pageCount: 0,
      ids: [],
      tableData: [],
      logs: [],
    };
  },
  methods: {
    // 导出
    doExport() {},
    handleSizeChange(pageSize) {
      this.params.pageSize = pageSize;
      this.params.pageIndex = 1;

      this.getDataStatistics();
    },
    handleCurrentChange(pageIndex) {
      this.params.pageIndex = pageIndex;
      this.getDataStatistics();
    },
    doSearch() {
      this.params.pageIndex = 1;
      this.getDataStatistics();
    },
    getDataStatistics() {
      // 加载优惠券列表
      getDataStatistics(this.params.pageIndex, this.params.pageSize, {
        batchId: this.params.batchId,
        batchName: this.params.batchName,
        applyName: this.params.applyName,
        createTime: this.params.createTime
      }).then((res) => {
        // Todo
        // 如果成功返回 设置数据
        // 否则提示
        if (res.code === 200) {
          this.tableData = res.result.records;
          this.totalCount = res.result.total;
          this.pageCount = res.result.pages;
        } else {
          this.tableData = [];
          this.emptyText = res.msg;
          this.totalCount = 0;
          this.pageCount = 0;
        }
      });
    },
    refresh() {
      this.pageIndex = 1;
      this.getDataStatistics();
    },
  },
  mounted() {
    // 加载优惠券列表
    this.getDataStatistics();
  },
};
</script>

<style lang="scss">
</style>